package com.google.code.puertorico.actors

import scala.actors.Actor
import com.google.code.puertorico._

object NextPlayerActor extends Actor {

  def act() {
    loop {
      react {
        case ActionSequence(state, actions) => {
          if (state.activePlayer == state.lastPlayerBeforeGovernor) {
            EndTurnActor ! ActionSequence(state, actions);
          } else {
            val card = state.activeStrategyCard;
            val newState = state.copy(activePlayer = state.nextActivePlayer);

            card match {
              case Builder(_) => BuilderActor ! ActionSequence(newState, actions);
              case Captain(_) => CaptainActor ! ActionSequence(newState, actions);
              case Craftsman(_) => CraftsmanActor ! ActionSequence(newState, actions);
              case Mayor(_) => MayorActor ! ActionSequence(newState, actions);
              case Prospector(_) => ProspectorActor ! ActionSequence(newState, actions);
              case Settler(_) => SettlerActor ! ActionSequence(newState, actions);
              case Trader(_) => TraderActor ! ActionSequence(newState, actions);
            }
          }
        }
      }
    }
  }
}